/*
作者: imsyy
主页：https://www.imsyy.top/
GitHub：https://github.com/imsyy/home
版权所有，请勿删除
*/
var names1="123";
//弹窗样式
iziToast.settings({
    timeout: 10000,
    progressBar: false,
    close: false,
    closeOnEscape: true,
    position: 'topCenter',
    transitionIn: 'bounceInDown',
    transitionOut: 'flipOutX',
    displayMode: 'replace',
    layout: '1',
    backgroundColor: '#00000040',
    titleColor: '#efefef',
    messageColor: '#efefef',
    icon: 'Fontawesome',
    iconColor: '#efefef',
    style: {
    maxWidth: '30px', // 核心：避免拉伸至屏幕宽度
    width: 'auto',     // 宽度自适应内容
    wordBreak: 'break-all' // 长文本自动换行
  }
});

/* 鼠标样式 */
const body = document.querySelector("body");
const element = document.getElementById("g-pointer-1");
const element2 = document.getElementById("g-pointer-2");
const halfAlementWidth = element.offsetWidth / 2;
const halfAlementWidth2 = element2.offsetWidth / 2;



function setPosition(x, y) {
    element2.style.transform = `translate(${x - halfAlementWidth2 + 1}px, ${y - halfAlementWidth2 + 1}px)`;
}

body.addEventListener('mousemove', (e) => {
    window.requestAnimationFrame(function () {
        setPosition(e.clientX, e.clientY);
    });
});


//加载完成后执行
window.addEventListener('load', function () {

    //载入动画
    $('#loading-box').attr('class', 'loaded');
    $('#bg').css("cssText", "transform: scale(1);filter: blur(0px);transition: ease 1.5s;");
    $('.cover').css("cssText", "opacity: 1;transition: ease 1.5s;");
    $('#section').css("cssText", "transform: scale(1) !important;opacity: 1 !important;filter: blur(0px) !important");

    //用户欢迎
setTimeout(function () {
names1=getwork("")
update()




    }, 800);

    //延迟加载音乐播放器
    let element = document.createElement("script");
    element.src = "./js/music.js";
    document.body.appendChild(element);



    //移动端去除鼠标样式
    if (Boolean(window.navigator.userAgent.match(/AppWebKit.*Mobile.*/))) {
        $('#g-pointer-2').css("display", "none");
    }

}, false)

setTimeout(function () {
    $('#loading-text').html("字体及文件加载可能需要一定时间")
}, 3000);

// 新春灯笼 （ 需要时可取消注释 ）
// new_element=document.createElement("link");
// new_element.setAttribute("rel","stylesheet");
// new_element.setAttribute("type","text/css");
// new_element.setAttribute("href","./css/lantern.css");
// document.body.appendChild(new_element);

// new_element=document.createElement("script");
// new_element.setAttribute("type","text/javascript");
// new_element.setAttribute("src","./js/lantern.js");
// document.body.appendChild(new_element);

//获取一言
fetch('https://v1.hitokoto.cn?max_length=24')
    .then(response => response.json())
    .then(data => {
        $('#hitokoto_text').html(data.hitokoto)
        $('#from_text').html(data.from)
    })
    .catch(console.error)

let times = 0;
$('#hitokoto').click(function () {
    if (times == 0) {
        times = 1;
        let index = setInterval(function () {
            times--;
            if (times == 0) {
                clearInterval(index);
            }
        }, 1000);
        fetch('https://v1.hitokoto.cn?max_length=24')
            .then(response => response.json())
            .then(data => {
                $('#hitokoto_text').html(data.hitokoto)
                $('#from_text').html(data.from)
            })
            .catch(console.error)
    } else {
        iziToast.show({
            timeout: 1000,
            icon: "fa-solid fa-circle-exclamation",
            message: '你点太快了吧'
        });
    }
});



//获取天气
//请前往 https://www.mxnzp.com/doc/list 申请 app_id 和 app_secret
//请前往 https://dev.qweather.com/ 申请 key
const add_id = "vcpmlmqiqnjpxwq1"; // app_id
const app_secret = "PeYnsesgkmK7qREhIFppIcsoN0ZShv3c"; // app_secret
const key = "691d007d585841c09e9b41e79853ecc2" // key
function getwork(text){
    pywebview.api.getworkmsg(text).then((response)=>{
         $('#workProgress .work-text span').html("");
        $('#classt').html("");
        if(response.length>0){

            $('#workProgress .work-text span').html(response[0][0]);
            $('#classt').empty();
            for(var i=0;i<response[0][1].length;i++){

                //$('#classt').prepend("<img  style='width:270px;' src=data:image/png;base64,"+response[i]+"></img> ");
                $('#classt').prepend("<br><spon  style='width:350px;' title='"+response[0][2][i]+"'>"+response[0][1][i]+"</spon><br>");
            }

            iziToast.show({
            timeout: 2500,
            icon: false,
            title: hello,
            message: response[1]
        });
        }else{
            ShowCreateModal()
        }
    })
}
function update(){
//$("#update_msg").attr("style","position:absolute;z-index:10;display:block;left: 35%;");
//$("#update_msg").attr("style","position:absolute;z-index:10;display:none;left: 35%;");
    pywebview.api.update().then((response)=>{
        $("#power").append(response.oldversion)
//       if(response.update){
//         $("#update_msg").attr("style","position:absolute;z-index:10;display:block;left: 35%;");
//        $("#version").html("存在新版本："+response.version)
//        $("#msg").html("更新内容："+response.msg)
//       }else{
////            iziToast.show({
////                    timeout: 3000,
////                    icon: "fa fa-check",
////                    message: '已是最新版'
////                });
//       }
    })

}
$("#goupdate").click(function () {
    $("#update_msg").attr("style","position:absolute;z-index:10;display:none;left: 35%;");
    pywebview.api.goupdate().then((response)=>{

    })
})
function greatqf(text){
    pywebview.api.greatqf(text).then((response)=>{
        iziToast.show({
                    timeout: 3000,
                    icon: "fa fa-check",
                    message: '运行成功'
                });
    })
    .catch(err => {
     iziToast.show({
                    timeout: 3000,
                    icon: "fa fa-check",
                    message: '异常'
                });
  })
}
// 修改弹出框的title, 显示弹框
function ShowCreateModal(){
    //$('#createFileMModal').modal('show');
    $('#createFileMModal').modal('show');
    $("#crmbtn").attr("style","display:block;");
    $("#greatqf").attr("style","display:none;");
    $('.modal-backdrop').remove();//移出遮罩层
}
// 关闭弹框， 获取输入值，然后执行逻辑
$("#createFileSureBut").click(function (){
    $("#createFileMModal").modal("hide");
    var crmid = $("#fileName").val();

    if(crmid!="" || crmid==null){
        getwork(crmid)
        $("#fileName").val("")
    }else{
//        const includeImageCheckbox = document.getElementById('includeImage');
//        // 获取选中状态（true 为选中，false 为未选中）
//        const isChecked = includeImageCheckbox.checked;
//        // 打印结果
        const data = {
          txt: encodeURIComponent($("#greatqftxt").val()),  // 空字符串
          check: $("#includeImage").prop("checked")  // 单选框的选中状态（true 或 false）
        };
        greatqf(data)
    }
});
$("#greatqfbtn").click(function (){
    $('#createFileMModal').modal('show');
    $("#greatqf").attr("style","display:block;");
    $("#crmbtn").attr("style","display:none;");
    $('.modal-backdrop').remove();//移出遮罩层
});

//群发弹窗逻辑
$("#nickname").click(function (){
    $ ('#greatqftxt').val ($ ('#greatqftxt').val () + '{nickname}');
});
$("#parent").click(function (){
    $ ('#greatqftxt').val ($ ('#greatqftxt').val () + '{parent}');
});
function getWeather() {
    fetch("https://www.mxnzp.com/api/ip/self?app_id=" + add_id + "&app_secret=" + app_secret)
        .then(response => response.json())
        .then(data => {
            let str = data.data.city
            let city = str.replace(/市/g, '')
            console.log(data,"sssss")
            $('#city_text').html(city);
            fetch("https://geoapi.qweather.com/v2/city/lookup?location=" + city + "&number=1&key=" + key)
                .then(response => response.json())
                .then(location => {
                    let id = location.location[0].id
                    fetch("https://devapi.qweather.com/v7/weather/now?location=" + id + "&key=" + key)
                        .then(response => response.json())
                        .then(weather => {
                            $('#wea_text').html(weather.now.text)
                            $('#tem_text').html(weather.now.temp + "°C&nbsp;")
                            $('#win_text').html(weather.now.windDir)
                            $('#win_speed').html(weather.now.windScale + "级")
                        })
                })
        })
        .catch(console.error);
}

getWeather("");

$("#workProgress").click(function () {
    getwork("")
})
let wea = 0;
$('#upWeather').click(function () {
    if (wea == 0) {
        wea = 1;
        let index = setInterval(function () {
            wea--;
            if (wea == 0) {
                clearInterval(index);
            }
        }, 60000);
        getWeather();

        iziToast.show({
            timeout: 2000,
            icon: "fa-solid fa-cloud-sun",
            message: '实时天气已更新'
        });
    } else {
        iziToast.show({
            timeout: 1000,
            icon: "fa-solid fa-circle-exclamation",
            message: '请稍后再更新哦'
        });
    }
});

//获取时间
let t = null;
t = setTimeout(time, 1000);

function time() {
    clearTimeout(t);
    dt = new Date();
    let y = dt.getYear() + 1900;
    let mm = dt.getMonth() + 1;
    let d = dt.getDate();
    let weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    let day = dt.getDay();
    let h = dt.getHours();
    let m = dt.getMinutes();
    let s = dt.getSeconds();
    if (h < 10) {
        h = "0" + h;
    }
    if (m < 10) {
        m = "0" + m;
    }
    if (s < 10) {
        s = "0" + s;
    }
    $("#time").html(y + "&nbsp;年&nbsp;" + mm + "&nbsp;月&nbsp;" + d + "&nbsp;日&nbsp;" + "<span class='weekday'>" + weekday[day] + "</span><br>" + "<span class='time-text'>" + h + ":" + m + ":" + s + "</span>");
    t = setTimeout(time, 1000);
}

//链接提示文字
$("#social").mouseover(function () {
    $("#social").css({
        "background": "rgb(0 0 0 / 25%)",
        'border-radius': '6px',
        "backdrop-filter": "blur(5px)"
    });
    $("#link-text").css({
        "display": "block",
    });
}).mouseout(function () {
    $("#social").css({
        "background": "none",
        "border-radius": "6px",
        "backdrop-filter": "none"
    });
    $("#link-text").css({
        "display": "none"
    });
});

$("#github").mouseover(function () {
    $("#link-text").html("去 Github 看看");
}).mouseout(function () {
    $("#link-text").html("通过这里联系我");
});
$("#qq").mouseover(function () {
    $("#link-text").html("有什么事吗");
}).mouseout(function () {
    $("#link-text").html("通过这里联系我");
});
$("#email").mouseover(function () {
    $("#link-text").html("来封 Email");
}).mouseout(function () {
    $("#link-text").html("通过这里联系我");
});
$("#bilibili").mouseover(function () {
    $("#link-text").html("来 B 站看看 ~");
}).mouseout(function () {
    $("#link-text").html("通过这里联系我");
});
$("#telegram").mouseover(function () {
    $("#link-text").html("你懂的 ~");
}).mouseout(function () {
    $("#link-text").html("通过这里联系我");
});



//更多页面切换
let shoemore = false;
$('#switchmore').on('click', function () {
    shoemore = !shoemore;
    if (shoemore && $(document).width() >= 990) {
        $('#container').attr('class', 'container mores');
        $("#change").html("Oops&nbsp;!");
        $("#change1").html("如果我对云说悄悄话，你会介意吗？");
    } else {
        $('#container').attr('class', 'container');
        $("#change").html("love&nbsp;yourself&nbsp;!");
        $("#change1").html("藏起来的秘密，不应该被发现哦");
    }
});

//更多页面关闭按钮
$('#close').on('click', function () {
    $('#switchmore').click();
});

//移动端菜单栏切换
let switchmenu = false;
$('#switchmenu').on('click', function () {
    switchmenu = !switchmenu;
    if (switchmenu) {
        $('#row').attr('class', 'row menus');
        $("#menu").html("<i class='fa-solid fa-xmark'></i>");
    } else {
        $('#row').attr('class', 'row');
        $("#menu").html("<i class='fa-solid fa-bars'></i>");
    }
});
//代码提交按
$('#submitcrmcode').on('click', function () {
    submitcode()
});
//提交代码
function submitcode() {
    var text="elk638798+Elk638798"
    var username=$("#username").val();
    var password=$("#password").val();
    var token=$("#token").val();
    pywebview.api.getstatus(username+"+"+password+"+"+token).then((response)=>{
        
        var htmls="";
        if(response.length>0){
            for(var i=0;i<response.length;i++){
                htmls+="<tr><td>"+response[i][0]+"</td><td>"+response[i][1]+"</td><td>"+response[i][2]+"</td><td>"+response[i][3]+"</td></tr>"
            }
        }else{
            iziToast.show({
                timeout: 1000,
                icon: "fa-solid fa-circle-exclamation",
                message: '未提交任何作业'
            });
        }
        $('#homework_table').html(htmls);
    })
}
//更多弹窗页面
$('#openmore').on('click', function () {
    $('#box').css("display", "block");
    $('#row').css("display", "none");
    $('#more').css("cssText", "display:none !important");
});
$('#closemore').on('click', function () {
    $('#box').css("display", "none");
    $('#row').css("display", "flex");
    $('#more').css("display", "flex");
});

//作业批改显示按钮
$('#homework_btn').on('click', function () {
pywebview.api.getteacher().then((response)=>{
    // 接下来判断是否是指定老师
        if(response=="蒋来老师"||response=="肖绮婷老师"){
            $('#homework_table').html("");
            $('#homework').css("display", "block");
            $('#row').css("display", "none");
        }else{
            iziToast.show({
                timeout: 2000,
                icon: "fa-solid fa-circle-exclamation",
                message: '无权使用！！'
            });
        }

    })


});
//生成规划按钮
$('#creatguihua').on('click', function () {
// 保存第一个通知的引用
let loadingNotification = iziToast.show({
        timeout: false,
        close: false,
        icon: "fa-solid fa-circle-exclamation",
        message: "正在创建规划表，请稍后"
    });
pywebview.api.creatght().then((response)=>{
     // 在第489行关闭上面的通知
     iziToast.destroy(loadingNotification);
     iziToast.show({
        timeout: 2000,
        icon: "fa-solid fa-circle-exclamation",
        message: response
    });
    
    })


});
//作业批改关闭按钮
$('#closehomework').on('click', function () {
    $('#box').css("display", "none");
    $('#homework').css("display", "none");
    $('#row').css("display", "flex");
});
$('#xingke').on('click', function () {
    $('#row2').css("display", "none");
    $('#row3').css("display", "block");
});
$('#copy').on('click', function () {
    $('#row2').css("display", "flex");
    $('#row3').css("display", "none");
	var jd = $('#selectkqqgg_jd option:selected')
	var ks = $('#selectkqqgg_ks option:selected')
	var kc = $('#selectkqqgg_kc option:selected')
	var lx = $('#selectkqqgg_lx option:selected')
	//ipcRenderer.send('copykqqgg', kc.val()+"+"+jd.val()+"+"+ks.val()+"+"+lx.val());
	var str=kc.val()+"+"+jd.val()+"+"+ks.val()+"+"+lx.val()
	pywebview.api.runclass(str).then((response)=>{
          console.log('提醒已启用');
        })

	iziToast.show({
        timeout: 2000,
        icon: "fa fa-check",
        message: '复制成功'
    });
});
$('#close1').on('click', function () {
    pywebview.api.quit().then((response)=>{})
});
$('#min1').on('click', function () {
    pywebview.api.min().then((response)=>{})
});

$('#xubao').on('click', function () {
    iziToast.show({
        timeout: 2000,
        icon: "fa-solid fa-circle-exclamation",
        message: '续报物料开发中！'
    });
});

//监听下拉列表

$("#selectkqqgg_kc").on('click', function () {
	
    var jd = $('#selectkqqgg_kc option:selected')
	
	var obj = document.getElementById("selectkqqgg_jd");
	var ks = document.getElementById("selectkqqgg_ks");
	obj.options.length = 0; 
	ks.options.length = 0;
	if(jd.val()=="两课思维"){
		obj.add(new Option("L2","1")); 
		obj.add(new Option("L3","2")); 
		obj.add(new Option("L4","3")); 
		obj.add(new Option("L5","4")); 
		obj.add(new Option("L6","5")); 
		obj.add(new Option("L7","6")); 
		
		ks.add(new Option("1","1")); 
		ks.add(new Option("2","2")); 
		ks.add(new Option("3","3")); 
		ks.add(new Option("4","4")); 
	}
	if(jd.val()=="莫顿思维"){
		obj.add(new Option("L2","1")); 
		obj.add(new Option("L3","2")); 
		obj.add(new Option("L4","3")); 
		obj.add(new Option("L5","4")); 
		obj.add(new Option("L6","5")); 
		obj.add(new Option("L7","6")); 
		
		ks.add(new Option("1","1")); 
		ks.add(new Option("2","2")); 
		ks.add(new Option("3","3")); 
		ks.add(new Option("4","4")); 
	}
	if(jd.val()=="一课算法"){
		obj.add(new Option("L9","1")); 
		obj.add(new Option("L10","2")); 
		obj.add(new Option("L11","3")); 
		obj.add(new Option("L12","4")); 
		obj.add(new Option("L13","5")); 
		obj.add(new Option("L14","6"));
		obj.add(new Option("L15","7"));
		
		ks.add(new Option("1","1")); 
		ks.add(new Option("2","2")); 
		ks.add(new Option("3","3")); 
		ks.add(new Option("4","4")); 
		ks.add(new Option("5","5")); 
		ks.add(new Option("6","6")); 
		ks.add(new Option("7","7")); 
	}
	if(jd.val()=="C1"){
		obj.add(new Option("L1","1"));
		obj.add(new Option("L2","2"));
		obj.add(new Option("L3","3"));
		obj.add(new Option("L4","4"));
		obj.add(new Option("L5","5"));
		obj.add(new Option("L6","6"));

		ks.add(new Option("1","1"));
		ks.add(new Option("2","2"));
		ks.add(new Option("3","3"));
		ks.add(new Option("4","4"));
	}
});

//监听网页宽度
window.addEventListener('load', function () {
    window.addEventListener('resize', function () {
        //关闭移动端样式
        if (window.innerWidth >= 600) {
            $('#row').attr('class', 'row');
            $("#menu").html("<i class='fa-solid fa-bars'></i>");
            //移除移动端切换功能区
            $('#rightone').attr('class', 'row rightone');
        }

        if (window.innerWidth <= 990) {
            //移动端隐藏更多页面
            $('#container').attr('class', 'container');
            $("#change").html("Hello&nbsp;World&nbsp;!");
            $("#change1").html("一个建立于 21 世纪的小软件，存活于互联网的边缘");

            //移动端隐藏弹窗页面
            $('#box').css("display", "none");
            $('#row').css("display", "flex");
            $('#more').css("display", "flex");
        }
    })
})

//移动端切换功能区
let changemore = false;
$('#changemore').on('click', function () {
    changemore = !changemore;
    if (changemore) {
        $('#rightone').attr('class', 'row menus mobile');
    } else {
        $('#rightone').attr('class', 'row menus');
    }
});

//AI对话显示关闭按钮
$("#more").click(function () {
    $('#close').css("display", "block");
}, function () {
    $('#close').css("display", "none");
})




//屏蔽右键
document.oncontextmenu = function () {
    iziToast.show({
        timeout: 2000,
        icon: "fa-solid fa-circle-exclamation",
        message: '为了使用体验，本软件禁用右键'
    });
    return false;
}

let btnNewwin1 = document.getElementById("qunfa");
let btnNewwin2 = document.getElementById("dabiaoq");
btnNewwin1.onclick = function(){
        pywebview.api.zq('tag.py').then((response)=>{
            if (response.length >0){
                iziToast.show({
                    timeout: 3000,
                    icon: "fa fa-check",
                    message: '运行成功'
                });
		        pywebview.api.shown().then((response)=>{
                })
		    }
        })
};
btnNewwin2.onclick = function(){
	     pywebview.api.xh('tag.py').then((response)=>{
            if (response.length >0){
                iziToast.show({
                    timeout: 3000,
                    icon: "fa fa-check",
                    message: '运行成功'
                });
		        pywebview.api.shown().then((response)=>{
                })
		    }
        })
};







//控制台输出
//console.clear();
let styleTitle1 = `
font-size: 20px;
font-weight: 600;
color: rgb(244,167,89);
`
let styleTitle2 = `
font-size:12px;
color: #425AEF;
`
let styleContent = `
color: rgb(30,152,255);
`
let title1 = 'Kaylaの主页'
let title2 = `

██████╗ ██╗   ██╗██╗    ██╗██╗███╗   ██╗██████╗ 
██╔══██╗╚██╗ ██╔╝██║    ██║██║████╗  ██║██╔══██╗
██████╔╝ ╚████╔╝ ██║ █╗ ██║██║██╔██╗ ██║██║  ██║
██╔══██╗  ╚██╔╝  ██║███╗██║██║██║╚██╗██║██║  ██║
██████╔╝   ██║   ╚███╔███╔╝██║██║ ╚████║██████╔╝
╚═════╝    ╚═╝    ╚══╝╚══╝ ╚═╝╚═╝  ╚═══╝╚═════╝               
`
let content = `
博客:  https://bolo.wuhobin.top
Github:  https://github.com/wuhobin
`
console.log(`%c${title1} %c${title2}
%c${content}`, styleTitle1, styleTitle2, styleContent)
